#ifndef _BEASTHTTPSERVER_H
#define __BEASTHTTPSERVER_H

#include "BeastHttpServerRequestHandler.h"

#include <boost/beast/http.hpp>
#include <boost/asio/ip/tcp.hpp>
#include <boost/asio/spawn.hpp>
#include <boost/beast/core.hpp>

#include <thread>

class BeastHttpServer:public std::enable_shared_from_this<BeastHttpServer>, boost::noncopyable
{
public:
    bool StartServer(uint16_t port, int thread_num = std::thread::hardware_concurrency());
    void SetRequestHandler(std::shared_ptr<BeastHttpServerRequestHandler> requestHandler);

private:
    void do_listen( boost::asio::yield_context yield);
    void do_session(boost::beast::tcp_stream& stream, boost::asio::yield_context yield);
private:
    boost::asio::io_context _ioc;
    boost::asio::ip::tcp::acceptor _acc{ _ioc};

    bool _IsServerStarted = false;

    std::shared_ptr<BeastHttpServerRequestHandler> _requestHandler = nullptr;
};

#endif
